package views;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;

@SuppressWarnings("serial")
public class SisLgnGUI extends JFrame {
	public JTextField tfLogin;
	public JPasswordField tfSenha;
	public JButton btLogar;
	public JButton btSair;
	
	private JFrame tela = this;
	
	public SisLgnGUI() {
		setType(Type.UTILITY);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Login");
		getContentPane().setLayout(null);
		setSize(new Dimension(205, 160));
		setLocationRelativeTo(null);
		setAlwaysOnTop(true);

		//Estilo dos components
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}	
		
		tfLogin = new JTextField();
		tfLogin.setBounds(71, 26, 89, 20);
		getContentPane().add(tfLogin);
		tfLogin.setColumns(10);
		tfSenha = new JPasswordField(6);
		tfSenha.setBounds(71, 56, 89, 20);
		getContentPane().add(tfSenha);
		
		JLabel lblNewLabel = new JLabel("Senha:");
		lblNewLabel.setLabelFor(tfSenha);
		lblNewLabel.setBounds(27, 59, 34, 14);
		getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Login:");
		lblNewLabel_1.setLabelFor(tfLogin);
		lblNewLabel_1.setBounds(27, 29, 46, 14);
		getContentPane().add(lblNewLabel_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		panel_1.setBounds(27, 87, 133, 26);
		getContentPane().add(panel_1);
		panel_1.setLayout(null);
		
		btLogar = new JButton("Logar");
		btLogar.setBounds(1, 1, 63, 23);
		panel_1.add(btLogar);
		
		btSair = new JButton("Sair");
		btSair.setBounds(68, 1, 63, 23);
		panel_1.add(btSair);
		
		JLabel lblNewLabel_2 = new JLabel("Vers\u00E3o 0.3");
		lblNewLabel_2.setForeground(Color.BLUE);
		lblNewLabel_2.setBounds(134, 1, 55, 14);
		getContentPane().add(lblNewLabel_2);
		new Thread(new Runnable() {			
			@Override
			public void run() {
				synchronized (this) {
					try {
						wait(100);
					} catch (Exception e) {
						// TODO: handle exception
					}
					Point p = tela.getLocation();
					p.y += 150;
					tela.setLocation(p);
				}
			}
		}).start();
	}

	public void setListener(ActionListener al) {	
		btLogar.addActionListener(al);
		btSair.addActionListener(al);
	}
}
